﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SmartSapce.ServiceLocation;
using SmartSpace.Core;
using SmartSpace.OA;
using SmartSpace.Web;

namespace SmartSpace.WebApp.Modules.OA.Pages
{
    public partial class Article_Create : SsTemplatePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ICoreService service = ServiceLocator.Get<ICoreService>();

                List<CodeDefinition> codes = service.GetCodeDefinitions(Article.TypeCategoryCode);
                _ctlListType.DataSource = codes;
                _ctlListType.DataBind();
            }
        }

        protected void _ctlBtnSave_Click(object sender, EventArgs e)
        {
            Article article = new Article();
            article.Id = Guid.NewGuid();
            article.Title = _ctlEditTitle.Text;
            article.Creator = User.Identity.Name;
            article.CreatedDate = DateTime.Now;
            article.TypeCaption = _ctlListType.SelectedItem.Text;
            article.TypeCode = _ctlListType.SelectedItem.Value;
            article.Content = _ctlEditContent.Text;

            IOAService service = ServiceLocator.Get<IOAService>();
            service.SaveArticle(article);
            Response.Redirect("./Article-list.aspx");
        }
    }
}